<?php
//生成批量插入数据库的语句。
//items数组
//values
//table

//$p['table']=$table_Prefix."detail";
//$p['items']=array("mid","name","include_gene","price","birthdays","sex","lengths","weight","local" ,"belong_term","belong_store","auto_name","url","publish","belong");
//$p['values']=$detail_list;
//
//


function insert_datas($array)
{


//获取数据库目标表格存入数组
    $items = mysql_query("SHOW COLUMNS FROM ".$array['table']."") ;

    while($row = mysql_fetch_array($items))
    {
        $table_item_list[]=$row['Field'];

    }



//$item_check=array_intersect($array['items'],$table_item_list);
$item_check=array_diff($array['items'],$table_item_list);



if(!$item_check)
    {

//        insert into persons
//
//    (id_p, lastname , firstName, city )
//
//values
//
//(200,'haha' , 'deng' , 'shenzhen'),
//
//(201,'haha2' , 'deng' , 'GD'),
//
//(202,'haha3' , 'deng' , 'Beijing');


    $items=implode(",",$array['items']);

    $sqlstr_prefix="insert into ".$array['table'];
    $sqlstr_mid="($items) values ";


    foreach($array['values'] as $k => $v)
    {

         $detail_list=implode("','",$v);
        //echo "<br/>";
        $sqlstr_surffix=$sqlstr_surffix."('".$detail_list."'),";
    }


    $sqlstr_surffix=rtrim($sqlstr_surffix,",");
    $result=$sqlstr_prefix.$sqlstr_mid.$sqlstr_surffix;

    }



    else
    {
        $result="表格项与插入项不一致";
    }




    return $result.implode(",",$item_check);
}


